package com.example.dao;

import java.util.Set;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.entity.StudentEntity;

@Mapper
public interface StudentDAO {

	@Insert({ "INSERT INTO student(id, name, gender, birthday, phone)",
			"VALUES(#{stu.id}, #{stu.name}, #{stu.gender}, #{stu.birthday}, #{stu.phone})" })
	int add(@Param("stu") StudentEntity studentEntity);

	@Update({ "<script>",
		     "UPDATE student SET status = -1 WHERE id IN",
			"<foreach item='id' collection='ids' open='(' separator=',' close=')'>",
			"#{id}",
			"</foreach>",
			"</script>"})
	int delete(@Param("ids") Set<Integer> ids);

	@Update({ "UPDATE student SET name= #{stu.name}, gender=#{stu.gender}, birthday=#{stu.birthday}, phone= #{stu.phone}",
		       "WHERE id=#{stu.id}"})
	int update(@Param("stu") StudentEntity studentEntity);

	@Select({ "SELECT * from student WHERE id = #{id}" })
	StudentEntity queryById(Integer id);
	
	@Select({"SELECT * FROM student"})
	StudentEntity queryAll();

}
